<?

require_once("cls_db.php");

class cls_user
{
	function insert_new_member($arr)
	{
		$db		= new db();
		$sql	= "INSERT INTO tbl_clogin (cname,cpassword) VALUES ('". $arr['username'] ."','". $arr['userpassword'] ."')";
		$db->execute_nonquery($sql);
		
		return mysql_insert_id();
	}
	
	function insert_new_coordinator($cname)
	{
		$db		= new db();		
		$sql	= "INSERT INTO tbl_coordinator (coordinator_id,coordinator_name) VALUES (". $_SESSION[id] .",'". $cname ."')";
		return $db->execute_nonquery($sql);
				
	}

	function insert_gbook($arr)
	{
		$db		= new db();
		$sql	= "INSERT INTO gbook (name,email,comment) VALUES ('". $arr['name'] ."','". $arr['email'] ."','". $arr['commentText'] ."')";
		//echo $sql;
		return $db->execute_nonquery($sql);
		
	}
	
	function get_gbook()
	{
		$db 	= new db();
		$sql	= "SELECT * FROM gbook ORDER BY id DESC LIMIT 5";

		$row = $db->get_all_data($sql);

		if (count($row)) {
			return $row;
		}
	}//get_gbook
	
//	function get_user($id,$pageno = 1)
	function get_user($pageno = 1)
	{
		$db 	= new db();
		$sql	= "SELECT * FROM tbl_clogin";
		
		$db->set_pageno($pageno);
		$result = $db->get_datalist($sql);

		$result['pagecount']	= $db->get_pagecount();
		$result['numrows']		= $db->get_numrows($sql);
		
		$db->db_close();
		
		return $result;

		//$row = $db->get_all_data($sql);

		//if (count($row)) {
			//return $row;
		//}
	}//get_user
	
	function delete_user($id)
	{
		$db		= new db();
		
		$sql = "Delete from tbl_clogin  where cid = $id";
		$db->execute_nonquery($sql);
		$sql = "Delete from tbl_coordinator  where coordinator_id = $id";
		$result  =	$db->execute_nonquery($sql);
		return $result;
		
	}
	
	function delete_gbook($id)
	{
		$db		= new db();
		
		$sql = "Delete from gbook where id = $id";
			
		return $db->execute_nonquery($sql);
		
	}
	
	function c_sign_in($arr)
	{
		$db		= new db();
		$sql	= "SELECT * FROM tbl_clogin ".
					"WHERE cname='".$arr['cname']."' AND cpassword='". $arr['cpassword'] ."'";
		//echo $sql;
		$result	= $db->execute_query($sql);
		$db->db_close();		
		return $result;
		
	}
	
}//class
?>